<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑</title>
    <link rel="stylesheet" href="/ssm/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/ssm/css/public.css" media="all">
    <script src="/ssm/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
    <style>
        .layui-form {
            margin-top: 20px;
        }

        .demo-login-container {
            width: 300px;
            margin: 0 auto;
        }
    </style>
</head>
<body>

<form class="layui-form" lay-filter='course'>
    <div class="demo-login-container">
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="hidden" name="id" >
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="text" name="courseName" lay-verify="required" placeholder="请输入课程名称"
                       autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <select name="typeId">
                    <option value="">请选择课程类型</option>
                    <option value="1">单车类</option>
                    <option value="2">身心类</option>
                    <option value="3">训练类</option>
                    <option value="4">舞蹈类</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <select name="coachId">
                    <option value="">请选择教练</option>
                    <option value="1">张三</option>
                    <option value="2">李四</option>
                    <option value="3">王五</option>
                    <option value="4">赵六</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <input type="number" name="price" lay-verify="required" placeholder="请输入课程价格" autocomplete="off"
                       class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <textarea name="comment" placeholder="请输入课程介绍"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-wrap">
                <button type="submit" class="layui-btn" lay-submit lay-filter="upload">更新课程</button>
            </div>
        </div>
    </div>
</form>


<script>
    layui.use(function () {
        let form = layui.form;
        let $ = layui.$;
        let layer = layui.layer;


        let course = JSON.parse(sessionStorage.getItem("course"))
        form.val('course', course)
        form.render()

        form.on("submit(upload)", function (obj) {
            let formData = obj.field;
            $.post("/ssm/course/update", formData, function (res) {
                if (res.code == 0) {
                    layer.msg(res.msg, {icon: 1}, function () {
                        // 关闭弹出层
                        let index = parent.layer.getFrameIndex(window.name); // 先得到当前 iframe 层的索引
                        parent.layer.close(index);
                    })
                } else {
                    layer.msg(res.msg, {icon: 2})
                }
            })
            return false;
        })
    })
</script>
</body>
</html>